#include <iostream>
#include <vector>

using namespace std;

int gcf(int, int);
int lcm(int, int);

int main()
{
    vector<int>f1(2);
    vector<int>f2(2);
    vector<int>res;
    char sp;
    cout << "请输入第一个分数(例如5/2):";
    cin >> f1[0] >> sp >> f1[1];
    cout << "请输入第二个分数(例如3/2):";
    cin >> f2[0] >> sp >> f2[1];
    if (f1[1] == f2[1])
    {
        res.push_back(f1[0] + f2[0]);
        res.push_back(f1[1]);
    }
    if (gcf(res[0], res[1]) == 0);
    else
    {
        int max, brk;
        while(brk != 1)
        {
            max = gcf(res[0], res[1]);
            if (max == 1)
            {
                brk = 1;
            }
            res[0] /= max;
            res[1] /= max;
        }
    }
    //如果能整除
    if(res[0] % res[1] == 0)
    {
        cout << "结果为：" << res[0] / res[1] << endl;
    }
    //不能整除的输出结果
    else
    {
        cout << "结果为：" << res[0] << "/" << res[1];
    }
    return 0;
}

int gcf(int num1, int num2)
{
    //储存最大公因数
    int res = 0;

    //计算最大公因数
    if (num1 > num2)
    {
        for(int i = 1; i <= num2; i++)
        {
            if(num1 % i == 0 && num2 % i ==0)
            {
                res = i;
            }
        }
    }
    else if (num1 == num2)
    {
        res = num1;
    }
    else
    {
        for(int i = 1;i <= num1; i++)
            if(num1 % i == 0 && num2 % i == 0)
            {
                res = i;
            }
    }

    //返回最大公因数
    return res;
}

int lcm(int num1, int num2)
{
    if (num1 > num2)
    {
        for(int i = num1; i <= INT_MAX; i++)
        {
            i % num1 == 0 && i % num2 == 0 : return i ? counitue;
        }
    }
}
